package edu.mju.vodtest;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.List;

/**
 * @Author:wyp
 * @Date:2020/9/13 16:49
 */
public class testVod {
    /*获取播放地址函数*/
    public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
        //创建获取视频地址的request
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        request.setVideoId("b03aa0871a774fb08e8a726357e29b90");
        return client.getAcsResponse(request);
    }

    /*获取播放凭证函数*/
    public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("e1032051e0ce4ae5b28419add470f07d");
        return client.getAcsResponse(request);
    }

    public static void main(String[] args) throws ClientException {
        getVideoPlayAuth();
    }

    public static void  getVideoPlayAuth() throws ClientException {
        DefaultAcsClient client = initObject.initVodClient("LTAI4GCXRzKPaVY11HGjzkBb", "96KHHrA9rLDQMb97FeC3Kz9DgDbRFj");
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        try {
            response = getVideoPlayAuth(client);
            //播放凭证
            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }

    public static void getPlayInfo() throws ClientException {
        //创建初始化对象
        DefaultAcsClient client = initObject.initVodClient("LTAI4GCXRzKPaVY11HGjzkBb", "96KHHrA9rLDQMb97FeC3Kz9DgDbRFj");
        //创建获取视频地址的response
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        try {
            response = getPlayInfo(client);
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }
}
